﻿Imports Aricie.DNN.UI.Controls

Namespace Aricie.DNN.Modules.LuceneSearch.UI

    Public Class HeaderTemplate
        Inherits AricieUserControlBase
        Implements ITemplate

        Public Event SortColumn As EventHandler

#Region "Private Attributes"
        Private WithEvents _btnUp As Button
        Private WithEvents _btnDown As Button
        Private _lblHeader As Label
        Private _nameField As String
#End Region

#Region "Public Properties"
        Public Property btnUp() As Button
            Get
                Return _btnUp
            End Get
            Set(ByVal value As Button)
                _btnUp = value
            End Set
        End Property

        Public Property btnDown() As Button
            Get
                Return _btnDown
            End Get
            Set(ByVal value As Button)
                _btnDown = value
            End Set
        End Property

        Public Property lblHeader() As Label
            Get
                Return _lblHeader
            End Get
            Set(ByVal value As Label)
                _lblHeader = value
            End Set
        End Property
#End Region

#Region "Constructeur"
        Public Sub New(ByVal nameHeaderToDisplay As String, ByVal nameField As String, ByVal allowSorting As Boolean)
            _nameField = nameField

            'Création du LabelHeader
            Dim myLblHeader As New Label
            myLblHeader.ID = "lblHeader" + nameField
            myLblHeader.Text = nameHeaderToDisplay
            Me.lblHeader = myLblHeader


            'Création du BoutonUp
            Dim myBtnUp As New Button
            myBtnUp.ID = "btnUp" + nameField
            myBtnUp.CssClass = "sortup"
            myBtnUp.Visible = allowSorting
            myBtnUp.Width = 16
            myBtnUp.Height = 16
            Me.btnUp = myBtnUp


            'Création du BoutonDown
            Dim myBtnDown As New Button
            myBtnDown.ID = "btnDown" + nameField
            myBtnDown.CssClass = "sortdn"
            myBtnDown.Visible = allowSorting
            myBtnDown.Width = 16
            myBtnDown.Height = 16
            Me.btnDown = myBtnDown

            AddHandler Me.btnUp.Click, AddressOf _btnUp_Click
            AddHandler Me.btnDown.Click, AddressOf _btnDown_Click

            If nameHeaderToDisplay = "" Then
                myBtnDown.Visible = False
                myBtnUp.Visible = False
                myLblHeader.Visible = False
            End If

        End Sub
#End Region

#Region "Implement ITemplate"
        Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
            container.Controls.Add(New LiteralControl("<table class='table_" + _nameField + "'><tr><td width='100%'>"))
            container.Controls.Add(Me.lblHeader)
            container.Controls.Add(New LiteralControl("</td><td align='right'>"))
            container.Controls.Add(Me.btnUp)
            container.Controls.Add(New LiteralControl("<br/>"))
            container.Controls.Add(Me.btnDown)
            container.Controls.Add(New LiteralControl("</td></tr></table>"))
        End Sub


#End Region


        Private Sub _btnDown_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim myButton As Button = CType(sender, Button)
            myButton.CssClass = "sortdnactif"
            RaiseEvent SortColumn(sender, e)
        End Sub

        Private Sub _btnUp_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim myButton As Button = CType(sender, Button)
            myButton.CssClass = "sortupactif"
            RaiseEvent SortColumn(sender, e)
        End Sub




    End Class

End Namespace
